<?php

namespace Kateba\AdminBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\SecurityContext;

/**
 * Admin controller.
 * @author Mahmoud
 */
class AdminController extends Controller {

    /**
     * the default login action
     * @return Response 
     */
    public function loginAction() {
        $request = $this->getRequest();
        $session = $request->getSession();

        // get the login error if there is one
        if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
            $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
        } else {
            $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
        }

        return $this->render('KatebaAdminBundle:Admin:login.html.twig', array(
                    // last username entered by the user
                    'last_username' => $session->get(SecurityContext::LAST_USERNAME),
                    'error' => $error,
                ));
    }

    /**
     * the default admin home page action
     * @return Response 
     */
    public function homeAction() {
        return $this->render('KatebaAdminBundle:Admin:home.html.twig');
    }

}
